package com.dp.service.impl3;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dp.util.DataMap;
import com.dp.vo.ClientComments;


@Service
@Transactional
public class ClientCommentsServiceImpl3 extends BaseImpl {

	/**
	 * Find the ClientComments Entity
	 * @param hashMap
	 * @param firstrow
	 * @param maxrow
	 * @return List<ClientComments>
	 */
	public List<ClientComments> findClientComments(DataMap hashMap, Integer firstrow,
			Integer maxrow){
		ClientComments clientComment=(ClientComments) hashMap.get("clientComment");
		String ccontent = hashMap.getMapData("ccontent");
		StringBuffer sf = new StringBuffer("SELECT cc FROM ClientComments cc WHERE 1=1 ");
			if(ccontent!=null&& ccontent.trim().length() > 0){
				sf.append(" AND cc.ccontent like '%"
						+ ccontent.trim() + "%'");
			}
		List<ClientComments> queryList=null;
		try {
			Query query = em.createQuery(sf.toString());
			if (firstrow != null) {
				query.setFirstResult(firstrow);
			}
			if (maxrow != null) {
				query.setMaxResults(maxrow);
			}
			queryList = query.getResultList();
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return queryList;
	}
	
	
	/**
	 * Delete ClientComments Entity
	 * @param urlB
	 * @return boolean b
	 */
	public boolean deleteClientCommentById(Integer cid) {
		logger.info("cid:"+cid);
		boolean b = false;
		try {
			ClientComments clientComment=em.find(ClientComments.class, cid);
			em.remove(clientComment);
			b = true;
		} catch (Exception e) {
			logger.info("deleteClientComment fail !!!" + e.getMessage());
			return b;
		} 
		return b;
	}

	public ClientComments addClientComment(ClientComments clientComment) {
		try {
			clientComment=em.merge(clientComment);
		} catch (Exception e) {
			logger.info("addClientComment fail !!!" + e.getMessage());
			clientComment=null;
		} 
		return clientComment;
	}
}
